package com.demoo.zjsu.service.smartwebsite.bwc;

import com.demoo.zjsu.model.smartwebsite.PageTwo;
import com.demoo.zjsu.model.smartwebsite.PageTwoContent;
import com.demoo.zjsu.service.smartwebsite.Page;
import com.demoo.zjsu.service.smartwebsite.PageFactoryExtend;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jshjsh on 2016/8/18.
 * 失物招领
 * http://bwc.zjgsu.edu.cn/ArticleShow.asp?bookid=1171
 */
@Service
public class LostAndFoundService extends PageFactoryExtend{


    @Override
    public List<String> getTimes(Elements elements) {
        ArrayList<String> arrayList = new ArrayList<String>();
        for (Element element : elements) {
            String time = element.select("[width=12%]").text();
            arrayList.add(time);
        }
        return arrayList;
    }

    @Override
    public Elements getOtherMain(Document document) {
        return document.select("[cellpadding=2]");
    }

    @Override
    public PageTwo dealTitle(String url, String title) {
        return new PageTwo(title, "", url.replace("ArticleShow.asp?", ""), 0);
    }

    @Override
    public void filterAgain(Elements elements) {
        elements.select("tr").eq(0).remove();
    }

    @Override
    public PageTwoContent getContent(Elements elements) {
        String throat = elements.select("tr").eq(0).text().replaceAll("已被浏览 .* 次", "");
        elements.select("tr").eq(0).remove();
        String content = elements.toString();
        return new PageTwoContent(content, throat);
    }

    @Override
    public Page getPage() {
        return new Page("http://bwc.zjgsu.edu.cn/ArticleList.asp?nid=34", "失物招领");
    }

    @Override
    public Elements getMain(Document document) {
        return document.select("[cellpadding=4]").eq(0).select("tr");
    }
}
